package cn.wolfcode.crm.config;

import cn.wolfcode.crm.web.interceptor.LoginInterceptor;
import cn.wolfcode.crm.web.interceptor.PermissionInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration


/*
* 添加拦截器在传统的XML方式中，我们需要在< mvc:interceptors >
标签中去注册我们自定义的拦截器，
* 在SpringBoot，只需要让我们的配置对象去实现WebMvcConfigurer接口，
* 实现接口中addInterceptors方法即可
* 让spring管理拦截器bean对象 , 在拦截器类上贴@Component注解
*
* */
public class MyMvcConfigurer implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    @Autowired
    private PermissionInterceptor permissionInterceptor;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册登录拦截器,传入拦截器对象
        registry.addInterceptor(loginInterceptor).
                addPathPatterns("/**").
                excludePathPatterns("/loginUser.do","/login.html","/css/**","/js/**");
        // 注册登录拦截器
        registry.addInterceptor(permissionInterceptor)
                // 对哪些资源起过滤作用
                .addPathPatterns("/**")
                // 对哪些资源起排除作用
                .excludePathPatterns("/loginUser.do","/login.html","/css/**","/js/**");
    }
}
